import axios from 'axios';
import fs from 'fs';

const fileId = '7ryM2G71XRVwkQnkklWrbI';
const nodeId = '0:2671'; // 从URL中提取的节点ID
const token = process.env.FIGMA_ACCESS_TOKEN;

console.log('🔍 获取特定节点设计数据...');
console.log('节点ID:', nodeId);

try {
  const response = await axios.get(`https://api.figma.com/v1/files/${fileId}/nodes`, {
    headers: { 'X-Figma-Token': token },
    params: { ids: nodeId }
  });
  
  console.log('✅ 节点数据获取成功!');
  const nodeData = response.data.nodes[nodeId];
  
  if (nodeData && nodeData.document) {
    console.log('节点名称:', nodeData.document.name);
    console.log('节点类型:', nodeData.document.type);
    console.log('尺寸:', `${nodeData.document.absoluteBoundingBox?.width || 0} x ${nodeData.document.absoluteBoundingBox?.height || 0}`);
    
    // 保存完整数据
    fs.writeFileSync('node-2671-data.json', JSON.stringify(nodeData, null, 2));
    console.log('💾 数据已保存到 node-2671-data.json');
    
    // 分析子元素
    if (nodeData.document.children) {
      console.log('\n📱 界面元素:');
      nodeData.document.children.forEach((child, index) => {
        console.log(`  ${index + 1}. ${child.name} (${child.type})`);
        if (child.absoluteBoundingBox) {
          console.log(`     位置: (${child.absoluteBoundingBox.x}, ${child.absoluteBoundingBox.y})`);
          console.log(`     尺寸: ${child.absoluteBoundingBox.width} x ${child.absoluteBoundingBox.height}`);
        }
      });
    }
  }
  
} catch (error) {
  console.log('❌ 获取失败:', error.response?.status, error.response?.statusText);
  console.log('错误详情:', error.response?.data);
}
